/*
 * TriggerHandle.java
 *
 * Created on 17 maart 2008, 21:09
 *
 * @author wijnand.schepens@hogent.be
 */

package diagram.handles;

import diagram.Node;
import diagram.locations.FlexibleRelativeLocation;
import diagram.locations.RectangleLineLocation;
import java.awt.Color;
import java.awt.Graphics2D;

public class TriggerHandle extends Handle
{
	protected int radius = 5; //default

    public TriggerHandle(){}

	public TriggerHandle(Node baseNode, int radius)
	{
		super(baseNode, new RectangleLineLocation(new FlexibleRelativeLocation(baseNode.getUpperLeft(), 0, 0),baseNode.getUpperLeft(), baseNode.getLowerRight()));
		this.radius = radius;
	}

    public TriggerHandle(Handle baseHandle, int radius)
	{
		super(baseHandle, new RectangleLineLocation(new FlexibleRelativeLocation(baseHandle.getUpperLeft(), 0, 0),baseHandle.getUpperLeft(), new FlexibleRelativeLocation(baseHandle.getUpperLeft(), 30, 15)));
		this.radius = radius;
	}
//    public void attach(Node n){
//        super.setLocation(new RectangleLineLocation(new FlexibleRelativeLocation(n.getUpperLeft(), 0, 0),n.getUpperLeft(), n.getLowerRight()));
//        super.setBaseNode(n);
//    }
//
//    public void detach(){
//        super.setLocation(new AbsoluteLocation(super.getLocation().getX(), super.getLocation().getY()));
//        super.setBaseNode(null);
//    }


	public void paint(Graphics2D g)
	{
		Color oldColor = g.getColor();

		g.setColor(Color.WHITE);
		g.fillOval(getLocation().getX()-radius, getLocation().getY()-radius, 2*radius, 2*radius);
		g.setColor(Color.BLACK);
		g.drawOval(getLocation().getX()-radius, getLocation().getY()-radius, 2*radius, 2*radius);
		if (highlighted)
			g.drawOval(getLocation().getX()-(radius+2), getLocation().getY()-(radius+2), 2*(radius+2), 2*(radius+2));

		g.setColor(oldColor);
	}

	public boolean contains(int x, int y)
	{
		return (getLocation().getX()-x)*(getLocation().getX()-x) + (getLocation().getY()-y)*(getLocation().getY()-y) <= radius*radius;
	}

//	public Location getConnectPoint()
//	{
//		return new RelativeLocation(this, 0, 0);
//	}




}
